package card;

import java.util.ArrayList;
import java.util.List;

import util.Rand;
import battle.BattleDao;
import entity.CardVo;

public class CardService {
	BattleDao battleDao=new BattleDao();
	/**
	 * 
	 * @param lowstar 最低星级
	 * @param highstar 最高星级
	 * @param topdroprate 最高级掉落率单位是1/10000
	 * @return
	 */
	public CardVo getOneCard(int lowstar,int highstar,int topdroprate){
		List<CardVo> one=battleDao.getCardListByStar(1);
		List<CardVo> two=battleDao.getCardListByStar(2);
		List<CardVo> three=battleDao.getCardListByStar(3);
		List<CardVo> four=battleDao.getCardListByStar(4);
		List<CardVo> five=battleDao.getCardListByStar(5);
		
		Rand rand=new Rand();
		int r=rand.getRand(10000);
		if(r<topdroprate){
			r=rand.getRand(five.size());
			return five.get(r);
		}else if(topdroprate<=r&&r<topdroprate*9){
			r=rand.getRand(four.size());
			return four.get(r);		
		}else if(topdroprate*9<=r&&r<topdroprate*9*9){
			r=rand.getRand(three.size());
			return three.get(r);
		}else if(topdroprate*9*9<=r&&r<topdroprate*9*9*9){
			r=rand.getRand(two.size());
			return two.get(r);
		}else{
			r=rand.getRand(one.size());
			return one.get(r);
		}		
	}
}
